#include <iostream>
#include <deque>
#include <algorithm>

using namespace std;

#define oo 1000000000

int t[101][101];
int d[101];
int res, pos, n;

int BFS(int start)
{
	deque<int> q;
	q.clear();
	q.push_back(start);

	for (int i = 1 ; i <= n; i++) d[i] = oo;
	d[start] = 0;

	while (!q.empty())
	{
		int u = q.front();
		q.pop_front();

		for (int v = 1; v <= n; v++) 
			if (d[v] > d[u] + t[u][v])
			{
				d[v] = d[u] + t[u][v];
				q.push_back(v);
			}
	}

	int maxd = -oo;
	for (int u = 1; u <= n; u++) maxd = max(d[u], maxd);

	return maxd;
}

int main()
{
	while (cin >> n)
	{
		if (n == 0) break;

		for (int i = 1; i <= n; i++) 
			for (int j = 1; j <= n; j++) t[i][j] = oo;

		for (int i = 1; i <= n; i++)
		{
			int m;
			cin >> m;
			for (int k = 0; k < m; k++)
			{
				int time, j;
				cin >> j >> time;
				t[i][j] = time;
			}			
		}

		res = oo;
		for (int i = 1; i <= n; i++)
		{
			int maxTime = BFS(i);

			if (res > maxTime)
			{
				res = maxTime;
				pos = i;
			}
		}
		if (res >= oo) cout << "disjoint" << endl;
		else cout << pos << " " << res << endl;
	}
}
